package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WhPrinterConfig;
import com.ruoyi.system.service.IWhPrinterConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 打印机配置Controller
 *
 * @author pangu
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/system/printer/config")
public class WhPrinterConfigController extends BaseController {
    @Resource
    private IWhPrinterConfigService whPrinterConfigService;

    /**
     * 查询打印机配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:printer:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(WhPrinterConfig whPrinterConfig) {
        startPage();
        List<WhPrinterConfig> list = whPrinterConfigService.selectWhPrinterConfigList(whPrinterConfig);
        return getDataTable(list);
    }

    /**
     * 获取打印机配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:printer:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(whPrinterConfigService.selectWhPrinterConfigById(id));
    }

    /**
     * 新增打印机配置
     */
    @PreAuthorize("@ss.hasPermi('system:printer:config:add')")
    @Log(title = "打印机配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WhPrinterConfig whPrinterConfig) {
        whPrinterConfig.setCreateBy(getUsername());
        return toAjax(whPrinterConfigService.insertWhPrinterConfig(whPrinterConfig));
    }

    /**
     * 修改打印机配置
     */
    @PreAuthorize("@ss.hasPermi('system:printer:config:edit')")
    @Log(title = "打印机配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WhPrinterConfig whPrinterConfig) {
        return toAjax(whPrinterConfigService.updateWhPrinterConfig(whPrinterConfig));
    }

    /**
     * 删除打印机配置
     */
    @PreAuthorize("@ss.hasPermi('system:printer:config:remove')")
    @Log(title = "打印机配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(whPrinterConfigService.deleteWhPrinterConfigByIds(ids));
    }
}
